using System.Xml;
using DeploymentWang.Interfaces.Entities;
using DeploymentWang.Interfaces.Resources;

namespace DeploymentWang.Core.Validators
{
    /// <summary>
    /// 
    /// </summary>
    public class ConfigXmlFileValidator : ConfigXmlFileOperationBase
    {
        protected override ConfigViolations DoOperation(ConfigurationRequest request,
            ConfigSetting setting,
            string targetLocation,
            XmlDocument xmlDoc, 
            XmlNode xmlNode)
        {
            if (!setting.IsActionDefined(DeploymentWangConstants.WellKnownActions.Validate))
                return new ConfigViolations();

            var violations = new ConfigViolations();

            if (string.CompareOrdinal(xmlNode.InnerText, setting.Value) != 0)
            {
                violations.Add(new ConfigViolation
                {
                    Message = string.Format("Value mismatch: expected '{0}', found '{1}'",
                    setting.Value, xmlNode.InnerText),
                    Info = setting
                });
            }

            return violations;
        }
    }
}